<script setup lang="ts">
import {reactive, ref} from 'vue';
import {ElMessage} from 'element-plus'
import {useAgentApi} from '/@/api/judicial/agent';

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh']);

// 定义变量
const ruleFormRef = ref(null);
const state = reactive({
	ruleForm: {

	},
	dialog: {
		loading: false,
		isShowDialog: false,
		title: '',
		submitTxt: '',
	}
});

const submitForm = () => {
	useAgentApi().agentSoftwareSubmit(state.ruleForm).then((res) => {
		if (res.code == 200) {
			ElMessage.success(res.message);
			closeDialog();
		} else {
			ElMessage.error(res.message);
		}
	})
};

// 打开弹窗
const openDialog = (title, row) => {
	state.dialog.title = title;
	state.dialog.submitTxt = '修 改';
	state.ruleForm = row;
	console.log('打开弹窗', state.ruleForm);
	state.dialog.isShowDialog = true;
};

// 关闭弹窗
const closeDialog = () => {
	state.dialog.isShowDialog = false;
	ruleFormRef.value.resetFields();
	emit('refresh');
};

// 暴露变量
defineExpose({
	openDialog,
});
</script>

<template>
	<view class="system-user-dialog-container">
		<el-dialog @close="closeDialog" :title="state.dialog.title" v-model="state.dialog.isShowDialog" width="700px">
			<el-form ref="ruleFormRef" :model="state.ruleForm" size="default" label-width="240px" status-icon class="demo-ruleForm">
				<el-row :gutter="35">
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="代理名称" prop="name">
							<el-input v-model="state.ruleForm.name"></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="程序端口" prop="name">
							<el-input v-model="state.ruleForm.port"></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="app_id" prop="app_id">
							<el-input v-model="state.ruleForm.app_id"></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="app_secret" prop="app_secret">
							<el-input v-model="state.ruleForm.app_secret"></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="商户号 | 支付宝：应用私钥" prop="merchant_id">
							<el-input v-model="state.ruleForm.merchant_id"></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="商户证书序列号 | 支付宝：平台公钥" prop="merchant_certificate_serial">
							<el-input v-model="state.ruleForm.merchant_certificate_serial"></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="apiv3公钥 | 支付宝：aes秘钥" prop="merchant_serial_key">
							<el-input v-model="state.ruleForm.merchant_serial_key"></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="商户支付证书私钥地址" prop="merchant_private_key_file_path">
							<el-input v-model="state.ruleForm.merchant_private_key_file_path"></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="微信支付平台证书私钥地址" prop="platform_certificate_file_path">
							<el-input v-model="state.ruleForm.platform_certificate_file_path"></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="平台（支付宝）公钥" prop="public_key">
							<el-input v-model="state.ruleForm.public_key"></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="应用私钥" prop="app_private_key">
							<el-input v-model="state.ruleForm.app_private_key"></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="应用公钥" prop="app_public_key">
							<el-input v-model="state.ruleForm.app_public_key"></el-input>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="支付宝aes秘钥" prop="aes_key">
							<el-input v-model="state.ruleForm.aes_key"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button type="primary" @click="submitForm" size="default">{{ state.dialog.submitTxt }}</el-button>
				</span>
			</template>
		</el-dialog>
	</view>
</template>

<style scoped lang="scss">

</style>